from types import FunctionType
from bitarray import test
from selenium import webdriver
from selenium.webdriver.common.by import By
import datetime
import time

browser = webdriver.Edge()

def browser_get():
    browser.get("http://windsgo.top")

def mtimer(fun : FunctionType):
    starttime = datetime.datetime.now()
    fun()
    endtime = datetime.datetime.now()
    elapsedtime = endtime - starttime
    print(elapsedtime)

def testthing():
    browser.get("https://dailyreport.sjtu.edu.cn/market/#/")
    reserve_name = "预约"
    reserve_class = ["NOT_RESERVE", "con_item_bt_btn"]
    Xpath = "//div[contains(text(),'" + reserve_name + "') \
            and contains(@class,'" + reserve_class[0] + "') \
            and contains(@class,'" + reserve_class[1] + "')]"
    
    while True:
        try:
            # browser.find_element(by=By.XPATH, value="//div[contains(@class,'NOT_RESERVE') and contains(@class, 'con_item_bt_btn')]")
            
            browser.find_element(by=By.XPATH, 
                                value=Xpath)
            print("ok")
            break
        except:
            print("failed")
    
    input()
    # while True:
    #     browser.refresh()
    

if __name__ == "__main__":
    testthing()